package com.ruoyi.system.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysCompanyMemberMapper;
import com.ruoyi.system.domain.SysCompanyMember;
import com.ruoyi.system.service.ISysCompanyMemberService;

import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;

/**
 * 企业项目成员Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-06-09
 */
@Service
public class SysCompanyMemberServiceImpl implements ISysCompanyMemberService 
{
    @Autowired
    private SysCompanyMemberMapper sysCompanyMemberMapper;

    /**
     * 查询企业项目成员
     * 
     * @param memberId 企业项目成员主键
     * @return 企业项目成员
     */
    @Override
    public SysCompanyMember selectSysCompanyMemberByMemberId(Long memberId)
    {
        return sysCompanyMemberMapper.selectSysCompanyMemberByMemberId(memberId);
    }

    /**
     * 查询企业项目成员列表
     * 
     * @param sysCompanyMember 企业项目成员
     * @return 企业项目成员
     */
    @Override
    public List<SysCompanyMember> selectSysCompanyMemberList(SysCompanyMember sysCompanyMember)
    {
        return sysCompanyMemberMapper.selectSysCompanyMemberList(sysCompanyMember);
    }

    /**
     * 新增企业项目成员
     * 
     * @param sysCompanyMember 企业项目成员
     * @return 结果
     */
    @Override
    public int insertSysCompanyMember(SysCompanyMember sysCompanyMember)
    {
        sysCompanyMember.setCreateTime(DateUtils.getNowDate());
        return sysCompanyMemberMapper.insertSysCompanyMember(sysCompanyMember);
    }

    /**
     * 修改企业项目成员
     *
     * @param sysCompanyMember 企业项目成员
     * @return 结果
     */
    @Override
    public int updateSysCompanyMember(SysCompanyMember sysCompanyMember)
    {
        sysCompanyMember.setUpdateTime(DateUtils.getNowDate());
        return sysCompanyMemberMapper.updateSysCompanyMember(sysCompanyMember);
    }

    /**
     * 批量删除企业项目成员
     *
     * @param memberIds 需要删除的企业项目成员主键
     * @return 结果
     */
    @Override
    public int deleteSysCompanyMemberByMemberIds(Long[] memberIds)
    {
        return sysCompanyMemberMapper.deleteSysCompanyMemberByMemberIds(memberIds);
    }

    /**
     * 删除企业项目成员信息
     *
     * @param memberId 企业项目成员主键
     * @return 结果
     */
    @Override
    public int deleteSysCompanyMemberByMemberId(Long memberId)
    {
        return sysCompanyMemberMapper.deleteSysCompanyMemberByMemberId(memberId);
    }

    /**
     * 新增企业项目成员
     *
     * @param sysCompanyMembers 企业项目成员
     * @return 结果
     */
    @Override
    public int insertSysCompanyMemberList(List<SysCompanyMember> sysCompanyMembers)
    {
        if(CollUtil.isNotEmpty(sysCompanyMembers)){
            for (SysCompanyMember sysCompanyMember:sysCompanyMembers){
                sysCompanyMember.setCreateTime(DateUtils.getNowDate());
                sysCompanyMember.setCreateBy(getLoginUser().getUsername());
            }
        }

        return sysCompanyMemberMapper.insertSysCompanyMemberList(sysCompanyMembers);
    }
}
